Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.GameGlobalVariable = undefined;
var BundleConfig = require("AA_BundleConfig");
var AudioManager = require("AA_AudioManager");
var EventManager = require("AA_EventManager");
var ResLoader = require("AA_ResLoader");
var EvenType = require("AA_EvenType");
var PlayerDataManager = require("AA_PlayerDataManager");
var Excel = require("AA_Excel");
var ExcelUtil = require("AA_ExcelUtil");
var UI_BulletMove = require("AA_UI_BulletMove");
var UI_MosterLogic = require("AA_UI_MosterLogic");
var NodePoolMag = require("AA_NodePoolMag");
var GameGlobalVariable = function () {
  function _creator() { }
  _creator.initPeiZhi = function () {
    _creator.huanyipi = this.getPeiZhiData("huanyipin");
    _creator.allhave = this.getPeiZhiData("allhave");
    _creator.shaodangtilicount = this.getPeiZhiData("saodangpower");
    _creator.kaishitilicount = this.getPeiZhiData("kaishipower");
    _creator.meirimianfeicount = this.getPeiZhiData("saodangfreecount");
    _creator.houlevelunlock = this.getPeiZhiData("houlevellunlock");
    _creator.wujintilicount = this.getPeiZhiData("wujintilicount");
    _creator.wujinsaodangcount = this.getPeiZhiData("wujinsaodangtilicount");
    _creator.wujinmeirifreecount = this.getPeiZhiData("wujinmeirifreecount");
    _creator.wujinunlockcount = this.getPeiZhiData("wujinunlockcount");
    _creator.addPowerTime = this.getPeiZhiData("addPowerTime");
    _creator.bagVideoCellCount = this.getPeiZhiData("bagVideoCellCount");
    _creator.severdatatime = this.getPeiZhiData("severdatatime");
    _creator.putongfuhuocount = this.getPeiZhiData("putongfuhuocount");
    _creator.wujinfuhuocount = this.getPeiZhiData("wujinfuhuocount");
    _creator.liulianlanguabomb = this.getPeiZhiData("liulianlanguabomb");
    _creator.wujinyinbicount = this.getPeiZhiData("wujinyinbicount");
    _creator.baggeizihelpopen = this.getPeiZhiData("baggeizihelpopen");
    _creator.wukongbishabili = this.getPeiZhiData("wukongbishabili");
    _creator.bagVideoResetCount = this.getPeiZhiData("bagVideoResetCount");
    _creator.beishustate = this.getPeiZhiData("beishustate");
    window.wx && window.wx.onShareAppMessage(function () {
      return {
        imageUrlId: "L1Vd19CmR3i/aikD7oi6AA==",
        imageUrl: "https://mmocgame.qpic.cn/wechatgame/HzPjqjMkXIeKHvHlQpQlOIhqrT16YcNugEZFHaeSnY0iaubd26dKyiaQtkVeXRyLTU/0",
        title: "吃不到我呀"
      };
    });
  };
  _creator.getWuJinYinBiCount = function () {
    var t = PlayerDataManager.PlayerDataMgr.dressUpArray.filter(function (e) {
      return 0 != e;
    }).length;
    var o = 0;
    var n = _creator.wujinyinbicount.length;
    for (var i = 0; i < n - 1; i++) {
      var a;
      if (t < (a = _creator.wujinyinbicount[i])[0]) {
        o = a[1];
        break;
      }
    }
    0 == o && (o = (a = _creator.wujinyinbicount[n - 1])[1]);
    return o;
  };
  _creator.getPeiZhiData = function (e) {
    var t = ExcelUtil.ExcelUtil.getSameData(Excel.Excel.shuiguoconfig_all, "configkey", e);
    if (t && t.length > 0) {
      if ("wujinyinbicount" == e) {
        return t[0].content;
      } else {
        return t[0].value;
      }
    } else {
      return {
        severdatatime: 3,
        huanyipin: 10,
        allhave: 3,
        saodangpower: 5,
        kaishipower: 5,
        saodangfreecount: 3,
        houlevellunlock: 4,
        wujintilicount: 5,
        wujinsaodangtilicount: 5,
        wujinmeirifreecount: 3,
        addPowerTime: 20,
        bagVideoCellCount: 3,
        wujinunlockcount: 4,
        putongfuhuocount: 999999,
        wujinfuhuocount: 1,
        liulianlanguabomb: .4,
        wujinyinbicount: [[2, 300], [6, 400], [6, 600]],
        baggeizihelpopen: 1,
        wukongbishabili: 4,
        bagVideoResetCount: 1,
        beishustate: 2
      }[e] || 0;
    }
  };
  _creator.jiluAttack = function (e, t) {
    var o = this.nowwShangHai[e];
    o || (o = 0);
    o += t;
    this.nowwShangHai[e] = o;
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_SHANGHAI_TONGJI);
  };
  _creator.cleanAttack = function () {
    this.nowwShangHai = {};
  };
  _creator.shaogunHit = function () {
    if (new Date().getTime() - this.offtime5 > 100) {
      AudioManager.AudioMgr.playEffect("game/sound/hit", false, BundleConfig.BundleNames.Game);
      this.offtime5 = new Date().getTime();
    }
  };
  _creator.playHitgunzi = function () {
    if (new Date().getTime() - this.offtime3 > 250) {
      AudioManager.AudioMgr.playEffect("game/sound/gunji", false, BundleConfig.BundleNames.Game);
      this.offtime3 = new Date().getTime();
    }
  };
  _creator.playHitJianShu = function () {
    if (new Date().getTime() - this.offtime1 > 3e3) {
      console.log("播放冻死梨子音效");
      AudioManager.AudioMgr.playEffect("game/sound/冻梨音效", false, BundleConfig.BundleNames.Game);
      this.offtime1 = new Date().getTime();
    }
  };
  _creator.playHitLiulian = function () {
    if (new Date().getTime() - this.offtimeLiuLian > 300 * Math.random()) {
      AudioManager.AudioMgr.playEffect("game/sound/榴莲打击", false, BundleConfig.BundleNames.Game);
      this.offtimeLiuLian = new Date().getTime();
    }
  };
  _creator.playHit = function () {
    if (new Date().getTime() - this.offtime > 500 * Math.random()) {
      AudioManager.AudioMgr.playEffect("game/sound/hit", false, BundleConfig.BundleNames.Game);
      this.offtime = new Date().getTime();
    }
  };
  _creator.playHitBomb1 = function () {
    if (new Date().getTime() - this.offbomb1time > 500 * Math.random()) {
      AudioManager.AudioMgr.playEffect("game/sound/南瓜炸弹", false, BundleConfig.BundleNames.Game);
      this.offbomb1time = new Date().getTime();
    }
  };
  _creator.playHitBomb2 = function () {
    if (new Date().getTime() - this.offbomb2time > 500 * Math.random()) {
      AudioManager.AudioMgr.playEffect("game/sound/西瓜爆炸", false, BundleConfig.BundleNames.Game);
      this.offbomb2time = new Date().getTime();
    }
  };
  _creator.isTeShuLevel = function () {
    if (-1 == _creator.nowlevel) {
      return 1;
    } else {
      return 2;
    }
  };
  _creator.subHuanYiPi = function () {
    this.huanyipi -= 1;
  };
  _creator.suballHave = function () {
    this.allhave -= 1;
  };
  _creator.getSceneId = function () {
    return (-1 == this.nowlevel ? Excel.Excel.shuiguotiaozhan(this.teshulevel) : Excel.Excel.shuiguoguanqia(this.nowlevel)).dipicture;
  };
  _creator.addNowLevelHuoBi = function (e) {
    this.nowlevelhuobi += e;
  };
  _creator.subNowLevelHuoBi = function (e) {
    this.nowlevelhuobi -= e;
  };
  _creator.paixuMoster = function (e) {
    var t = e.getComponentsInChildren(UI_MosterLogic.default);
    var o = [];
    var n = [];
    for (var i = 0; i < t.length; i++) {
      var a = t[i];
      if (!a.isDie || !a.isback) {
        var r = cc.Vec2.subtract(cc.v2(), cc.v2(), a.node.getPosition());
        var c = Math.atan2(r.y, r.x);
        var s = 180 / Math.PI * c + 180;
        if (s >= 0 && s <= 90) {
          o.push({
            jiaoben: s,
            script: a
          });
        } else {
          n.push({
            jiaoben: s,
            script: a
          });
        }
      }
    }
    o.sort(function (e, t) {
      if (e.jiaoben > t.jiaoben) {
        return -1;
      } else {
        return 1;
      }
    });
    n.sort(function (e, t) {
      if (e.jiaoben > t.jiaoben) {
        return -1;
      } else {
        return 1;
      }
    });
    var u = [];
    return (u = u.concat(o)).concat(n);
  };
  _creator.LanGuaPaiXu = function (e, t) {
    var o = [];
    var n = [];
    for (var i = 0; i < e.length; i++) {
      var a = e[i];
      a.setBoxState(false);
      var r = cc.Vec2.subtract(cc.v2(), cc.v2(), a.node.getPosition());
      var c = Math.atan2(r.y, r.x);
      var s = 180 / Math.PI * c + 180;
      if (s >= 0 && s <= 90) {
        o.push({
          jiaoben: s,
          script: a
        });
      } else {
        n.push({
          jiaoben: s,
          script: a
        });
      }
    }
    o.sort(function (e, t) {
      if (e.jiaoben > t.jiaoben) {
        return -1;
      } else {
        return 1;
      }
    });
    n.sort(function (e, t) {
      if (e.jiaoben > t.jiaoben) {
        return -1;
      } else {
        return 1;
      }
    });
    var u = this.paixuMoster(t)[0];
    if (u && (o.length > 0 || n.length > 0)) {
      if (u.jiaoben > 0 && u.jiaoben < 90) {
        n.forEach(function (e) {
          e.script.setBoxState(true);
        });
        o.forEach(function (e) {
          if (e.jiaoben > u.jiaoben + 20) {
            e.script.setBoxState(false);
          } else {
            e.script.setBoxState(true);
          }
        });
      } else {
        o.forEach(function (e) {
          e.script.setBoxState(false);
        });
        n.forEach(function (e) {
          if (e.jiaoben > u.jiaoben + 20) {
            e.script.setBoxState(false);
          } else {
            e.script.setBoxState(true);
          }
        });
      }
    }
  };
  _creator.addMoveBullet = function (e) {
    this.movebullets.push(e);
    if (-1 == this.ishavetime) {
      this.sendMoveBullet();
      this.ishavetime = setInterval(this.sendMoveBullet.bind(this), 200);
    }
  };
  _creator.cleanMoveBullet = function () {
    clearInterval(this.ishavetime);
    this.movebullets = [];
    this.ishavetime = -1;
  };
  _creator.sendMoveBullet = function () {
    return __awaiter(this, undefined, undefined, function () {
      var t;
      var o;
      var n;
      var r;
      return __generator(this, function (i) {
        switch (i.label) {
          case 0:
            if (this.movebullets.length > 0) {
              t = this.movebullets.shift();
              if (o = NodePoolMag.NodePoolMag.instance.getNode("bullet_3")) {
                return [3, 2];
              } else {
                return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Game, "game/prefabs/bullet/bullet3", cc.Prefab)];
              }
            } else {
              return [3, 3];
            }
          case 1:
            n = i.sent();
            NodePoolMag.NodePoolMag.instance.createNodeCount("bullet_3", 1, n);
            o = NodePoolMag.NodePoolMag.instance.getNode("bullet_3");
            i.label = 2;
          case 2:
            r = _creator.paths.children[5].convertToWorldSpaceAR(cc.v2());
            r = _creator.liulianNode.convertToNodeSpaceAR(r);
            o.x = r.x;
            o.y = r.y;
            o.scale = 1;
            _creator.liulianNode.addChild(o);
            setTimeout(function () {
              o.getComponent(UI_BulletMove.default).initBullet(t);
            }, 10);
            return [3, 4];
          case 3:
            clearInterval(this.ishavetime);
            this.ishavetime = -1;
            i.label = 4;
          case 4:
            return [2];
        }
      });
    });
  };
  _creator.getMosterDis = function (e, t) {
    var o = e.node.x;
    var n = e.node.y;
    var i = e.moveindex;
    var a = t.children;
    switch (e.moveindex) {
      case 1:
        (o += 100) > a[0].x && (o = a[0].x);
        break;
      case 2:
        if ((n += 100) > a[1].y) {
          var r = n - a[1].y;
          n = a[1].y;
          o = a[1].x + r;
          i -= 1;
        }
        break;
      case 3:
        if ((o -= 100) < a[2].x) {
          r = Math.abs(o - a[2].x);
          o = a[2].x;
          n = a[2].y + r;
          i -= 1;
        }
        break;
      case 4:
        if ((n -= 100) < a[3].y) {
          r = Math.abs(n - a[3].y);
          o = a[3].x - r;
          n = a[3].y;
          i -= 1;
        }
        break;
      case 5:
        if ((o += 100) > a[4].x) {
          r = Math.abs(o + a[4].x);
          o = a[4].x;
          n = a[4].y - r;
          i -= 1;
        }
    }
    return {
      pos: cc.v2(o, n),
      tagindex: i
    };
  };
  _creator.generateEquidistantCoordinates = function (e, t, o, n, i, a, r, c) {
    undefined === a && (a = 1);
    var s = [];
    for (var u = 0; u < i; u++) {
      var l = e;
      if (1 == a && (l = e + o * u) > c) {
        break;
      }
      if (2 == a && (l = e - o * u) < c) {
        break;
      }
      var d = t;
      if (3 == a && (d = t + n * u) > c) {
        break;
      }
      if (4 == a && (d = t - n * u) < c) {
        break;
      }
      s.push({
        pos: cc.v2(l, d),
        tagindex: r
      });
    }
    return s;
  };
  _creator.fenlieCreateMoster = function (e, t) {
    var o = t.children;
    var n = 2;
    var i = [];
    for (var a = e.moveindex; a > 0; a--) {
      var r = e.node.x;
      var c = e.node.y;
      var s = 0;
      var u = 0;
      var l = [];
      switch (a) {
        case 5:
          s = o[a].y;
          u = o[a].x;
          a == e.moveindex && (u = r);
          l = this.generateEquidistantCoordinates(u, s, 50, 0, n, 1, a, o[4].x);
          break;
        case 1:
          s = o[a].y;
          u = o[a].x;
          a == e.moveindex && (u = r);
          l = this.generateEquidistantCoordinates(u, s, 50, 0, n, 1, a, o[0].x);
          break;
        case 2:
          s = o[a].y;
          u = o[a].x;
          a == e.moveindex && (s = c);
          l = this.generateEquidistantCoordinates(u, s, 0, 50, n, 3, a, o[1].y);
          break;
        case 3:
          s = o[a].y;
          u = o[a].x;
          a == e.moveindex && (u = r);
          l = this.generateEquidistantCoordinates(u, s, 50, 0, n, 2, a, o[2].x);
          break;
        case 4:
          s = o[a].y;
          u = o[a].x;
          a == e.moveindex && (s = c);
          l = this.generateEquidistantCoordinates(u, s, 0, 50, n, 4, a, o[3].y);
      }
      if (l.length >= n) {
        i = i.concat(l.slice(0, n));
        break;
      }
      n -= l.length;
      i = i.concat(l);
    }
    return i;
  };
  _creator.setNewGame = function () {
    cc.sys.localStorage.setItem("isnewgame", 1);
  };
  _creator.getNewGame = function () {
    return !cc.sys.localStorage.getItem("isnewgame");
  };
  _creator.openName = function (e) {
    "" == this.ingName || (this.endName = this.ingName);
    this.ingName = e;
    console.log("场景路径", this.endName, this.ingName);
  };
  _creator.getNowName = function () {
    return this.ingName;
  };
  _creator.getEndName = function () {
    return this.endName;
  };
  _creator.nowlevel = 1;
  _creator.teshulevel = 1;
  _creator.nowlevelhuobi = 0;
  _creator.selfMap = {};
  _creator.bulletNode = null;
  _creator.languaNode = null;
  _creator.liulianNode = null;
  _creator.mosterNode = null;
  _creator.effNode = null;
  _creator.jinjieeffNode = null;
  _creator.playereffNode = null;
  _creator.paths = null;
  _creator.huanyipi = 0;
  _creator.allhave = 0;
  _creator.shaodangtilicount = 0;
  _creator.kaishitilicount = 0;
  _creator.meirimianfeicount = 0;
  _creator.houlevelunlock = 0;
  _creator.wujintilicount = 0;
  _creator.wujinsaodangcount = 0;
  _creator.wujinmeirifreecount = 0;
  _creator.wujinunlockcount = 0;
  _creator.putongfuhuocount = 0;
  _creator.wujinfuhuocount = 0;
  _creator.liulianlanguabomb = 0;
  _creator.wujinyinbicount = null;
  _creator.wukongbishabili = 0;
  _creator.baggeizihelpopen = 0;
  _creator.beishustate = 0;
  _creator.jiasuState = 1;
  _creator.isPad = false;
  _creator.diyicijin = false;
  _creator.severdatatime = 3;
  _creator.addPowerTime = 0;
  _creator.bagVideoCellCount = 0;
  _creator.bagVideoResetCount = 1;
  _creator.gamepuase = false;
  _creator.isZhanChunBug = false;
  _creator.gamefuhuo = false;
  _creator.adddimond = 0;
  _creator.addjinbi = 0;
  _creator.addpower = 0;
  _creator.normalMaxLevel = 4;
  _creator.zaZhongMaxLevel = 5;
  _creator.viewofftime = 0;
  _creator.isFirstGuide = false;
  _creator.nowwShangHai = {};
  _creator.offtime5 = 0;
  _creator.offtime3 = 0;
  _creator.offtime1 = 0;
  _creator.offtimeLiuLian = 0;
  _creator.offtime = 0;
  _creator.offbomb1time = 0;
  _creator.offbomb2time = 0;
  _creator.movebullets = [];
  _creator.ishavetime = -1;
  _creator.endName = "";
  _creator.ingName = "";
  return _creator;
}();
exports.GameGlobalVariable = GameGlobalVariable;